<?php

namespace App\Admin\Controllers;

use App\ParkChannel;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Illuminate\Http\Request;
use App\Park;

class ParkChannelController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Request $request,Content $content)
    {
        return $content
            ->header('园区频道')
            ->description('园区频道')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('园区频道详情')
            ->description('园区频道详情')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('园区频道编辑')
            ->description('园区频道编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新建园区频道')
            ->description('新建园区频道')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ParkChannel);

        $grid->id('Id');
        $grid->image('自定义海报');
        $grid->des('底部内容');
        $grid->column('pindao','频道管理')->display(function($vlaue){
            return "<a href='/admin/parkBaner?id={$this->id}' target='_self'> 编辑</a>";
        });
        $grid->created_at('创建时间');
        $grid->updated_at('更新时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ParkChannel::findOrFail($id));

        $show->id('Id');
        $show->image('自定义海报');
        $show->des('底部内容');
        $show->created_at('创建时间');
        $show->updated_at('更新时间');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ParkChannel);

        $form->select('park_id', '园区')->options(Park::getSelectOptions())->rules('required',['required'=>'请选择园区']);
        $form->image('image', '自定义海报')->rules('required',[
            'required'=>'请选择海报'
        ])->help('必填项');
        $form->ckeditor('des', '底部内容')->rules('required',[
            'required'=>'请输入厂房标题'
        ])->help('必填项');

        return $form;
    }
}
